package com.example.trb.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateFormatUtil {
    private static final SimpleDateFormat dateTimeFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private static final SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
    private static final SimpleDateFormat yearFormatter = new SimpleDateFormat("yyyy");

    public static String dateTimeToString(Date date) {
        return dateTimeFormatter.format(date);
    }

    public static String dateToString(Date date) {
        return dateFormatter.format(date);
    }

    public static Date stringToDate(String str) throws ParseException {
        return dateFormatter.parse(str);
    }

    public static String nowYear() {
        return yearFormatter.format(new Date());
    }

    public static String dateStrToYear(String date) {
        return date.substring(0, 4);
    }
}
